.group
  =f.label :program_id
  -if !f.object.new_record?
    =link_to f.object.program.display_name,
      edit_program_path(f.object.program)
  -else
    =f.collection_select :program_id, Program.all, :id, :display_name, {}, {:class => :collection, :multiple => false}
    :javascript
      old_slug_value = ""
      $('#control_program_id').change(function() {
        $.get("#{slug_programs_path}", {"id": $('#control_program_id').val()}, function(data) {
          if ($("#control_slug")[0].value == old_slug_value)
            $("#control_slug")[0].value = data[0]
            old_slug_value = data[0]
        }, "json");
      });

-if !f.object.new_record?
  .group
    =f.label :sections_id
    =f.collection_select :section_ids, f.object.program.sections, :id, :display_name, {}, {:class => :collection, :multiple => true}

  :javascript
    $('#control_section_ids').multiselect(
    {
      noneSelectedText: "Select",
      selectedList: 4,
      minWidth: 500,
    }).multiselectfilter(
    {
    });

.group
  =f.label :title
  =f.text_field :title, :class => :text_field

.group
  =f.label :slug
  =f.text_field :slug, :class => :text_field

.group
  =f.label :description
  =f.text_area :description, :class => :text_area

.group
  =f.label :frequency
  =f.text_field :frequency, :class => :text_field

.group
  =f.label :frequency_type
  =f.select :frequency_type, Control::FREQUENCIES, {:class => :enum}

.group
  =f.check_box :is_key, :class => :check_box
  =f.label :is_key, "Key control"

.group
  =f.check_box :fraud_related, :class => :check_box
  =f.label :fraud_related

.group
  =f.check_box :technical, :class => :check_box
  =f.label :technical

.group
  =f.label :assertion
  =f.text_field :assertion, :class => :text_field

.group
  =f.label :effective_at
  =f.text_field :effective_at, :class => :text_field, :value => (f.object.effective_at || Date.today).strftime("%Y-%m-%d")

.group
  =f.label :business_area_id
  =f.collection_select :business_area_id, BusinessArea.all, :id, :display_name, {}, {:class => :collection}

.group
  =f.label :test_result_id
  =f.collection_select :test_result_id, TestResult.all, :id, :display_name, {}, {:class => :collection}

.group.navform.wat-cf
  =f.submit pat(:save), :class => :button
  =f.submit pat(:cancel), :onclick => "window.location='#{controls_path}';return false", :class => :button

-if f.object.program && f.object.program.company?
  %hr.section
  %h3 Regulatory Controls
  %table.table
    %tr
      %th Name
      %th
    -edit_many(f.object, :control_controls, :implemented_control, :other_controller => :controls) do |bpc|
      &nbsp;

-if f.object.program && !f.object.program.company?
  %hr.section
  %h3 Consolidated Controls
  %table.table
    %tr
      %th Name
      %th
    -edit_many(f.object, :implementing_control_controls, :control, :other_controller => :controls) do |bpc|
      &nbsp;

-if f.object.program && !f.object.program.company?
  %hr.section
  %h3 Implemented Sections
  %table.table
    %tr
      %th Name
      %th
    -edit_many(f.object, :control_sections, :section, :other_controller => :sections) do |bpc|
      &nbsp;

-if f.object.program && f.object.program.company?
  %hr.section
  %h3 Biz Processes
  %table.table
    %tr
      %th Name
      %th State
      %th Ticket
      %th
    -edit_many(f.object, :biz_process_controls, :biz_process) do |bpc|
      %td
        State: 
        %span{:class => bpc.state}
          =bpc.state.to_s.capitalize
      %td
        Ticket: 
        =bpc.ticket
  -edit_many_attach(f.object, :biz_process_controls, :biz_process)

/=render :partial => 'base/model_history', :locals => { :object => f.object }
/  %hr.section
/  %h3 Systems
/  -edit_children(f.object, :system)
/
/  %hr.section
/  %h3 Evidence Descriptors
/  -edit_many_anon(f.object, :evidence_descriptor, :document_descriptor)
/
/  %hr.section
/  %h3 Implemented Controls
/  -edit_many_anon(f.object, :implemented_control, :control)
